<template>
	<view class="rece-container">
		<view v-if="exist">
			<view v-for="(item,index) in data" :key="index">
				<view class="rece-title">
					<text>{{item.date}}</text>
				</view>
				<view class="rece-content" v-for="(val,sub) in item.val" :key="sub">
					<image class="goods-img" :src="val.proimgs" mode="aspectFill" @click="navTo(val.proid)"></image>
					<view class="rece-texts">
						<view class="goods-details">{{val.proname}}</view>
						<view class="item-del">
							<text class="goods-price">￥{{val.nowprice}}</text>
							<!-- <image src="/static/imgs/car-icon.png" mode="aspectFill"></image> -->
							<!-- <text class="icon-delect" @click="del(val,sub)">删除</text> -->
							<view class="delBtn">
								<text @click="del(val,sub)">删除</text>
							</view>
						</view>
						
						<view style="clear: both;"></view>
					</view>
					<view style="clear: both;"></view>
				</view>
				
			</view>
			
		</view>
		
		<!-- 缺省页 start-->
		<view class="default-page" v-else>
			<image src="/static/imgs/defaultPage/viewHistory.png" mode="aspectFill"></image>
			<view>
				您暂时没有浏览过任何商品呦~
			</view>
			<view class="button">
				<button @click="switchTab('/pages/user/user')" class="bt1">个人中心</button>
				<button @click="switchTab('/pages/index/index')">首页</button>
			</view>
		</view>
		<!-- 缺省页 end-->
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
				exist: true,
			};
		},
		onLoad() {
			this.getData();
		},
		onPullDownRefresh() {
			this.getData();
		},
		methods: {
			navTo(id) {
				uni.navigateTo({
					url: `/pages/detail/detail?proid=${id}`
				})
			},
			async getData() {
				let a = await this.$http.getCurrentHistory();
				uni.stopPullDownRefresh();
				this.data = a.data;
				console.log("==============")
				console.log(this.data)
				console.log("==============")
				this.data.length == 0 ? this.exist = false : this.exist = true;
				
			},
			async del(val, index) {
				let a = await this.$http.delProHistory({
					proid: val.proid,
					date: val.date
				});
				if (a.code == 200) {
					this.getData();
					this.data.length == 0 ? this.exist = false : this.exist = true;
					uni.showToast({
						title: a.message,
						icon: 'none'
					});
					return
				}
				uni.showToast({
					title: a.message,
					icon: 'none'
				});
			},
			switchTab(url) {
				uni.switchTab({
					url
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
@import 'static/css/set.scss';
</style>
